﻿$(function(){
    var queryString = nehnre.queryString();
	var departmentId = queryString["departmentId"];
	if(departmentId){
	    $("#departmentId").val(departmentId);
		$(".STYLE4").wrap("<a href='../ZP/SelfExaminationView.aspx?DepartID={0}'></a>".format(departmentId));
	} else {
	    alert("条件不符合，没有部门ID!");
	    location.href="../Login.aspx";
	    return;
	}
    $( "#caseTime" ).datepicker({
	    monthNames:['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']	,
		showMonthAfterYear: true,
		dayNamesMin:['日', '一', '二', '三', '四', '五', '六'],
		firstDay:1,
		selectOtherMonths :true,
		showOtherMonths :true,
		dateFormat: 'yy-mm-dd',
		prevText:'上一月',
		nextText:'下一月',
		changeYear:true
	});
	$("#formID").validationEngine();
	
	var ilId = queryString["ilId"];
	if(ilId){
		$("#ilId").val(ilId);
		loadIllustrativecase(ilId);
	}
	
	$.ajax({
	    url:"ashx/load_depart_by_id.ashx",
	    data:"departmentId={0}".format(departmentId),
	    success:function(data){
	        $("#departmentName").html(data);
	    }
	});	
});

function loadIllustrativecase(ilId){
	$.ajax({
	    url:"ashx/load_illustrativecase.ashx",
	    data:"ilId={0}".format(ilId),
	    success:function(data){
	        console.log(arguments);
	        data = nehnre.parseJSON(data);
			if(data){
				$("#caseNum").val(data.caseNum);
				$("#caseTime").val(data.caseTime.split(" ")[0]);
				$("#caseReason").val(data.caseReason);
				$("#caseResult").val(data.caseResult);
				if(data.lastSaveTime){
					$("#lastSaveTime").html("最后修改：" + data.lastSaveTime);
				} else {
					$("#lastSaveTime").html("填写日期：" + new Date().format("yyyy-MM-dd hh:mm:ss"));
				}
			} else {
				alert("数据载入异常！");
			}
	    }
	});
}